<template>
  <div class="new">
    <div class="header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>物业服务</el-breadcrumb-item>
        <el-breadcrumb-item>活动管理</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/home/AnnouncementManagement' }">
          新建公告
        </el-breadcrumb-item>
      </el-breadcrumb>
      <h1>新建公告</h1>
    </div>

    <div class="content">
      <p>基础信息</p>
      <el-form label-width="120px">
        <el-form-item label="活动标题">
          <el-input v-model="name" />
        </el-form-item>
        <el-form-item label="作者">
          <el-input v-model="name" />
        </el-form-item>
      </el-form>
    <div style="width:900px;margin-left:120px;border: 1px solid #ccc">
        <Toolbar
          style="width: 900px; border-bottom: 1px solid #ccc"
          :editor="editorRef"
          :defaultConfig="toolbarConfig"
          :mode="mode"
        />
        <Editor
          style="height: 300px; width: 900px; overflow-y: hidden"
          v-model="valueHtml"
          :defaultConfig="editorConfig"
          :mode="mode"
          @onCreated="handleCreated"
        />
      </div>
      <div style="display: flex;justify-content: center;margin-top: 10px;">
        <el-button type="primary" @click="onSubmit">提交</el-button>
      <el-button>返回</el-button>
      </div>
     
    </div>
  </div>
</template>

<script>
import "@wangeditor/editor/dist/css/style.css"; // 引入 css

import { onBeforeUnmount, ref, shallowRef, onMounted } from "vue";
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
import { reactive } from 'vue'

export default {
  components: { Editor, Toolbar },
  setup() {
    // 编辑器实例，必须用 shallowRef
    const editorRef = shallowRef();
    const name='';
    // 内容 HTML
    const valueHtml = ref("<p>hello</p>");

    // 模拟 ajax 异步获取内容
    onMounted(() => {
      setTimeout(() => {
        valueHtml.value = "<p>模拟 Ajax 异步设置内容</p>";
      }, 1500);
    });

    const toolbarConfig = {};
    const editorConfig = { placeholder: "请输入内容..." };

    // 组件销毁时，也及时销毁编辑器
    onBeforeUnmount(() => {
      const editor = editorRef.value;
      if (editor == null) return;
      editor.destroy();
    });

    const handleCreated = (editor) => {
      editorRef.value = editor; // 记录 editor 实例，重要！
    };

    return {
      editorRef,
      valueHtml,
      mode: "default", // 或 'simple'
      toolbarConfig,
      editorConfig,
      handleCreated,
    };
  },
};
</script>

<style lang="less" scoped>
.new {
  height: 100%;
  background: #f0f2f5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  .header {
    width: 1136px;
    background: white;
    height: 100px;
    margin: 20px 0;
    .el-breadcrumb {
      height: 37px;
      line-height: 37px;
      font-size: 14px;
      margin-left: 30px;
      :deep(.el-breadcrumb__item:first-child .el-breadcrumb__inner) {
        color: #aaadb4;
      }
    }
    h1 {
      height: 60px;
      line-height: 60px;
      margin-left: 30px;
      font-family: "Microsoft Tai Le Bold", "Microsoft Tai Le", sans-serif;
      font-weight: 700;
      font-style: normal;
      font-size: 20px;
    }
  }
  .content {
    width: 1136px;
    background: white;
    height: 705px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    p {
      margin: 30px 0 20px 40px;
    }
    .el-form{
      width: 400px;
    }
  }
}
</style>
